Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: early exit for fail() #322

Merged
merged 8 commits into from
Jul 17, 2024
Merged

perf: early exit for fail() #322

merged 8 commits into from
Jul 17, 2024

Conversation

daejunpark
Copy link
Collaborator

@daejunpark daejunpark commented Jun 29, 2024

fix fail() to exit early.

previously, fail() was treated as a normal evm exception, allowing execution to continue after returning to the caller if any. (see the new test as example.) such continued execution is unnecessary. now fail() exits immediately, avoiding potential performance degradation.

@daejunpark daejunpark changed the title perf: early exist for fail() perf: early exit for fail() Jul 16, 2024
@@ -20,6 +20,22 @@ class NotConcreteError(HalmosException):
pass


class HalmosTargetReached(Exception):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please feel free to suggest a better name

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it sounds a little too semantically charged for me, I would go for something more descriptive like RunEndingException(Exception), and I would make both HalmosException and FailCheatcode inherit from RunEndingException:

class RunEndingException(Exception):
    """
    Base class for any exception that should not just stop the current EVM context, instead aborting the current test run. 
    """

    pass


class HalmosException(RunEndingException):
    """
    Base class for unexpected internal errors happening during a test run. 
    Inherits from RunEndingException because it should not just stop the current EVM context, but stop the whole run. 
    """

    pass


class FailCheatcode(RunEndingException):
    """
    Raised when invoking DSTest's fail() pseudo-cheatcode.
    Inherits from RunEndingException because it should not just stop the current EVM context, but stop the whole run. 
    """

    pass

Copy link
Collaborator

@karmacoma-eth karmacoma-eth Jul 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some alternatives along the same idea:

  • AbortCallException (not great, Call is ambiguous there)
  • AbortTestException
  • TestStopException
  • RunHaltException (Halt is neat)
  • HaltAndCatchFireException if you don't mind a fun reference 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for suggestion! i ended up with PathEndingException, because "run" is ambiguous with the entire test run.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, love it ♥️

fail();
}

function check_early_fail_cheatcode(uint x) public {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice test 👍

@daejunpark daejunpark merged commit 40cf25a into main Jul 17, 2024
53 checks passed
@daejunpark daejunpark deleted the perf/early-exit-fail branch July 17, 2024 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants